package Java复习;

import Java学习.Jpanel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;

class 高骑岳 extends JFrame {
    public 高骑岳() {
        jm();
        scree();
        this.setVisible(true);
    }
    public void scree(){
        this.setTitle("进制转换");
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
        this.pack();
    }
    public void jm(){
        JPanel jPanel1 = new JPanel();
        jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER));
        JLabel jLabel1 = new JLabel("请输入十进制数");
        TextField field1 = new TextField(10);
        jPanel1.add(jLabel1);
        jPanel1.add(field1);
        this.add(jPanel1, BorderLayout.NORTH);
        JPanel jPanel2 = new JPanel();
        TextArea area1 = new TextArea("",5,30, TextArea.SCROLLBARS_VERTICAL_ONLY);
        JLabel jLabel2 = new JLabel("请选择进制");
        jPanel2.add(area1);
        jPanel2.add(jLabel2);
        this.add(jPanel2, BorderLayout.CENTER);
        JPanel jPanel3 = new JPanel();
        jPanel3.setLayout(new GridLayout(2,1));
        JPanel jPanel4 = new JPanel();
        jPanel4.setLayout(new FlowLayout(FlowLayout.CENTER));
        JCheckBox jCheckBox1 = new JCheckBox();
        JLabel jLabel3 = new JLabel("二进制");
        JCheckBox jCheckBox2 = new JCheckBox();
        JLabel jLabel4 = new JLabel("八进制");
        JCheckBox jCheckBox3 = new JCheckBox();
        JLabel jLabel5 = new JLabel("十六进制");
        JCheckBox jCheckBox4 = new JCheckBox();
        JLabel jLabel6 = new JLabel("十进制");
        jPanel4.add(jCheckBox1);
        jPanel4.add(jLabel3);
        jPanel4.add(jCheckBox2);
        jPanel4.add(jLabel4);
        jPanel4.add(jCheckBox3);
        jPanel4.add(jLabel5);
        jPanel4.add(jCheckBox4);
        jPanel4.add(jLabel6);
        jPanel3.add(jPanel4);
        JPanel jPanel5 = new JPanel();
        jPanel5.setLayout(new FlowLayout(FlowLayout.CENTER));
        JLabel jLabel7 = new JLabel("请选择进制：");
        JRadioButton jRadioButton1 = new JRadioButton();
        JLabel jLabel8 = new JLabel("二进制");
        JRadioButton jRadioButton2 = new JRadioButton();
        JLabel jLabel9 = new JLabel("八进制");
        JRadioButton jRadioButton3 = new JRadioButton();
        JLabel jLabel10 = new JLabel("十六进制");
        JRadioButton jRadioButton4 = new JRadioButton();
        JLabel jLabel11 = new JLabel("十进制");
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(jRadioButton1);
        buttonGroup.add(jRadioButton2);
        buttonGroup.add(jRadioButton3);
        buttonGroup.add(jRadioButton4);
        jPanel5.add(jLabel7);
        jPanel5.add(jRadioButton1);
        jPanel5.add(jLabel8);
        jPanel5.add(jRadioButton2);
        jPanel5.add(jLabel9);
        jPanel5.add(jRadioButton3);
        jPanel5.add(jLabel10);
        jPanel5.add(jRadioButton4);
        jPanel5.add(jLabel11);
        jPanel3.add(jPanel5);
        this.add(jPanel3, BorderLayout.SOUTH);
        field1.addTextListener(new TextListener() {
            @Override
            public void textValueChanged(TextEvent e) {
                Long num = new Long(field1.getText());
                if (jRadioButton1.isSelected()){
                    area1.setText(Long.toBinaryString(num));
                }else if (jRadioButton2.isSelected()){
                    area1.setText(Long.toOctalString(num));
                }else if (jRadioButton3.isSelected()){
                    area1.setText(Long.toHexString(num));
                }else {
                    area1.setText(field1.getText());
                }
            }
        });
    }
}
public class 图形Num3 {
    public static void main(String[] args) {
        高骑岳 gqy = new 高骑岳();
    }
}
